<?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 15/12/3
 * Time: 11:14
 */

namespace Test\Controller;

use Common\Api\BoyeServiceApi;
use Admin\Model\SecurityCodeModel;

class TestUserController extends TestController{


    public function index(){

        $this->display();
    }

    public function register(){
        if(IS_POST){

            $data = array(
                'username'=> I('post.username',''),
                'password'=> I('post.password',''),
                'code'=> I('post.code',''),
                'reg_type'=> I('post.reg_type',''),
                'sex'=> I('post.sex',''),
                'email'=> I('post.email',''),
                'invite_id' => I('post.invite_id',''),
                'api_ver'=>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_register',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);

        }

        $this->display();
    }


    public function login(){

        if(IS_POST){

            $data = array(
                'username'=> I('post.username',''),
                "password"=> I('post.password',''),
                'api_ver'=>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_login',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,true);

            $this->parseResult($result);

        }

        $this->display();
    }

    public function update(){
        if(IS_POST){
            $data = array(
                'uid'=> I('post.uid',0),
                'mobile'=> I('post.mobile',''),
                'realname'=> I('post.realname',''),
                'idnumber'=> I('post.idnumber',''),
                'email'=> I('post.email',''),
                'birthday'=> I('post.birthday',0),
                'nickname'=> I('post.nickname',''),
                'sex'=> I('post.sex',''),
                'qq'=> I('post.qq',''),
                'head'=> I('post.head',''),
                'api_ver'=>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_update',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result= $service->callRemote("",$data,true);

            $this->parseResult($result);

        }

        $this->display();
    }

    public function findPswByMobile(){
        if(IS_POST){
            $data = array(
                'mobile'=>I('post.mobile',''),
                'code'=>I('post.code',''),
                'psw'=>I('post.psw',''),
                'api_ver'=>$this->api_ver,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_findPswByMobile',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result= $service->callRemote("",$data,true);

            $this->parseResult($result);

        }
        $this->display();
    }

    public function getCode(){
        $mobile = I('post.mobile','');
        $tpye = I('post.type','');

        $data = array(
            'mobile'=>$mobile,
            'code_type'=>$tpye,
            'api_ver'=>100,
            'notify_id'=>$this->notify_id,
            'type'=>'BY_Message_send_sms',
            'alg'=>'md5',
        );

        $service = new BoyeServiceApi();

        $result= $service->callRemote("",$data,false);
        if($result['status']){
            $info = $result['info'];
            if($info['status']){
                $this->success($info);
            }else{
                $this->error($info);
            }
        }else{
            $this->error($result['info']);
        }
    }

    public function deviceBind(){
        if(IS_POST){
            $data = array(
                'device_token'=>I('post.device_token',''),
                'uid'=>I('post.uid',0),
                'version'=>I('post.version',0),
                'device_type'=>I('post.device_type','Unknown'),
                'phone_type'=>I('post.phone_type',""),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_Device_bind',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);

        }
        $this->display();
    }

    public function addressAdd(){

        if(IS_POST){
            $data = array(
                'mobile' => I('post.mobile',0),
                'provinceid' => I('post.provinceid',''),
                'contactname' => I('post.contactname',''),
                'cityid' => I('post.cityid',''),
                'areaid' => I('post.areaid',''),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_addressAdd',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);

        }
        $this->display();

    }

    public function addressQuery(){
        if(IS_POST){
            $data = array(
                'uid' => I('post.uid',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_addressQuery',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();

    }

    public function addressDelete(){

        if(IS_POST){
            $data = array(
                'id' => I('post.id',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_addressDelete',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();

    }

    public function weixinChangePhone(){
        if(IS_POST){
            $data = array(
                'uid' => I('post.uid',0),
                'mobile'=>I('post.mobile',0),
                'code'=>I('post.code',0),
                'ori_mobile'=>I('post.ori_mobile',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_weixinChangePhone',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();
    }

    public function changePhone(){
        if(IS_POST){
            $data = array(
                'uid' => I('post.uid',0),
                'mobile'=>I('post.mobile',0),
                'code'=>I('post.code',0),
                'password'=>I('post.password',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_changePhone',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();

    }

    public function bind(){
        if(IS_POST){
            $data = array(
                'uid' => I('post.uid',0),
                'mobile'=>I('post.mobile',0),
                'code'=>I('post.code',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_changePhone',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();
    }

    public function loginByCode(){
        if(IS_POST){
            $data = array(
                'mobile'=>I('post.mobile',0),
                'code'=>I('post.code',0),
                'api_ver'=>100,
                'notify_id'=>$this -> notify_id,
                'type'=>'BY_User_loginByCode',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service -> callRemote("",$data,True);

            $this -> parseResult($result);
        }
        $this -> display();
    }


    public function updatePsw(){
        if(IS_POST){
            $data = array(
                'username' => I('post.username',0),
                'old_psw' => I('post.old_psw',0),
                'psw' => I('post.psw',0),
                'api_ver'=>100,
                'notify_id'=>$this->notify_id,
                'type'=>'BY_User_updatePsw',
                'alg'=>'md5',
            );

            $service = new BoyeServiceApi();

            $result = $service->callRemote("",$data,True);

            $this->parseResult($result);
        }
        $this->display();
    }

    private function parseResult($result){
        echo "解密后数据：";
        dump($result);
    }


}